#!/usr/bin/python
import sys, os, commands, string, re

class xxkill:
	def __init__(self):
		pass
	
	def kill_all(self, cmd):
		result = commands.getstatusoutput(cmd)
		list = string.split(result[1],'\n')
		for line in list:
			if line.find(cmd) < 0 and line.find('grep ') < 0 :
				listField = re.split(' *', line)
				commands.getstatusoutput('sudo kill -9 ' + listField[1])
	
	def help(self):
		cmd = sys.argv[0]
		print 'Please use the following cmd:'
		print '    ' + cmd + ' "ps -ef | grep <user> | grep <program>"'
		print 'e.g.'
		print '    ' + cmd + ' "ps -ef | grep kongxx | grep java"'
	
if len(sys.argv) == 2:
	cmd = sys.argv[1]
	t = xxkill()
	t.kill_all(cmd)
else:
	t = xxkill()
	t.help()

